package com.jsy.mini12306.ticketsales.controller;

import com.jsy.mini12306.ticketsales.service.DrivingPlanService;
import com.jsy.mini12306.ticketsales.vo.DrivingPlanVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.time.LocalDate;
import java.util.List;

/**
 * @author: SongyangJi
 * @description:
 * @since: 2021/9/2
 */

@Slf4j
@RestController
@RequestMapping("train")
public class DrivingPlanController {

    /**
     * 服务对象
     */
    @Resource
    private DrivingPlanService drivingPlanService;

    @GetMapping("/tickets")
    public ResponseEntity<List<DrivingPlanVO>> getTrainsByStartCityAndEndCity(@RequestParam String startCity, @RequestParam String endCity) {
        return ResponseEntity.ok(drivingPlanService.queryTrainsFromStartCityToEndCity(startCity, endCity));
    }

    @GetMapping("/tickets/date")
    public ResponseEntity<List<DrivingPlanVO>> getTrainsByStartCityAndEndCity(@RequestParam String startCity, @RequestParam String endCity, String dateStr) {
        List<DrivingPlanVO> drivingPlans = drivingPlanService.queryTrainsFromStartCityToEndCity(startCity, endCity, LocalDate.parse(dateStr));
        return ResponseEntity.ok(drivingPlans);
    }


}
